using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FitnessClub.Bll.StaffManager;
using System.Collections.Generic;

public partial class EmployeesHolidaysAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (StateManager.Instance.IsNullInSession(SessionKeys.EmployeeId))
            Response.Redirect("Employees.aspx");
        if (!IsPostBack)
        {
//            calFrom.SelectedDate = DateTime.Now;
//            calTo.SelectedDate = DateTime.Now.AddDays(1);
        }
    }
    protected void btnPowrot_Click(object sender, EventArgs e)
    {
        Response.Redirect("EmployeesHolidays.aspx");
    }
    protected void btnZapisz_Click(object sender, EventArgs e)
    {
        int employeeId = StateManager.Instance.GetFromSession<int>(SessionKeys.EmployeeId);
        ReqUEmp req = new ReqUEmp();
        if (calFrom.SelectedDate < DateTime.Now.AddYears(-2))
            lblFromRequired.Visible = true;
        else
            lblFromRequired.Visible = false;
        if (calFrom.SelectedDate > calTo.SelectedDate || calTo.SelectedDate < DateTime.Now.AddYears(-2))
            lblToRequired.Visible = true;
        else
            lblToRequired.Visible = false;
        if ((calFrom.SelectedDate < DateTime.Now.AddYears(-2)) || (calFrom.SelectedDate > calTo.SelectedDate || calTo.SelectedDate < DateTime.Now.AddYears(-2)))
            return;

        req.StartDay = calFrom.SelectedDate;
        req.EndDay = calTo.SelectedDate;
        req.Description = tbxDescription.Text;
        req.Type = int.Parse(ddlHolidayTypes.SelectedValue);
        req.EmployeeId = StateManager.Instance.GetFromSession<int>(SessionKeys.EmployeeId);
        bool result = Delegate.setUrlopEmployee(req);
        if (result)
            Response.Redirect("EmployeesHolidays.aspx");
        else
            lblError.Visible = true;
    }
}
